﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
namespace RippleEffect
{
    public class RippleEffect
    {
        
       
        private Grid MainCanvas = null;

        private RectangleGeometry Geo = new RectangleGeometry();

       
        private Grid CreateCanvas(Brush BackGround)
        {
            Grid RippleElement = new Grid();
            
            
            RippleElement.Background = BackGround;
            Geo.Rect = new Rect(0, 0, 200, 200);
            RippleElement.Clip = Geo;
            RippleElement.SizeChanged += new SizeChangedEventHandler(RippleElement_SizeChanged);       
            return RippleElement;
        }

        void RippleElement_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            Geo.Rect=new Rect(0,0,e.NewSize.Width,e.NewSize.Height);            
        }

     

        public RippleEffect(Panel E)
        {
            E.SizeChanged += new SizeChangedEventHandler(E_SizeChanged);
            MainCanvas = CreateCanvas(E.Background);
            MainCanvas.SetValue(Canvas.ZIndexProperty, -1);
            E.Children.Add(MainCanvas);
        }

        void E_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            MainCanvas.Width = e.NewSize.Width;
            MainCanvas.Height = e.NewSize.Height;
        }

        public void CircularRipple(double Radius,double RippleThickness,Point Center,double Duration,double RippleCount,ImageSource RippleImage)
        {
            Ripple r = new Ripple(Radius, RippleThickness, Center,this.MainCanvas,Duration,RippleCount,RippleImage);
            r.RunRippleAnimation();
           
        }
        

        
    }
}
